# Maintainer: Christian Rebischke <chris.rebischke@archlinux.org>

pkgname=ko
pkgver=0.15.1
pkgrel=1
pkgdesc="Build and deploy Go applications on Kubernetes"
arch=('loong64' 'x86_64')
url="https://github.com/google/ko"
license=('Apache')
makedepends=('go' 'git')
depends=('glibc')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/google/ko/archive/refs/tags/v${pkgver}.tar.gz")
sha512sums=('0fac42224a124b2c86125e2a33e01d2903cc0ec268a5b6814daf0259864fa269f9a1e9fc78ac66b19d20480503b9ae204163737c9030ba9fca7d165ee4b69c9f')
b2sums=('92170edf3c859ee9a9be365cec25e2ae57a6d4e5bfb779ae5557e872c04e1c606719e6fbd9e2f06dbe43156354ab54cc9564ee6dcb683794cc3fce59ae6963a5')

build() {
  cd "${pkgname}-${pkgver}"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
  go build -ldflags="-w -s -linkmode=external" .
  chmod +x ./ko
}

check() {
  cd "${pkgname}-${pkgver}"
  # currently disabled
  #go test -v -x ./...
}

package() {
  cd "${pkgname}-${pkgver}"
  install -Dsm755 ./ko "${pkgdir}/usr/bin/ko"
  mkdir -p "${pkgdir}/usr/share/bash-completion/completions/"
  mkdir -p "${pkgdir}/usr/share/zsh/site-functions/"
  mkdir -p "${pkgdir}/usr/share/fish/vendor_completions.d/"
  ./ko completion > "${pkgdir}/usr/share/bash-completion/completions/ko"
  ./ko completion zsh > "${pkgdir}/usr/share/zsh/site-functions/_ko"
  ./ko completion completion fish > "${pkgdir}/usr/share/fish/vendor_completions.d/ko.fish"
}
